/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!		
  \file		prpex_enum.h
  \date		june 2011
  \author		TNick

  \brief		enum class


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read ReadMe.txt and Licence.txt in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __PRPEX_ENUM_INC__
#define __PRPEX_ENUM_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<QString>
#include	"prpmdl.h"
#include	"prptpl.h"

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/// class representing a enum
/**
*	enums are diffrent from all other types; they are hosting subitems
*	and are the only type allowed at top level
*/
class PEX_Enum : public PrpTpl		{

	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:

	/// the index of the current (selected) entry in enum
	int				i_index;

	/// list os strings representing enum entries
	QStringList		qsl_enum;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:

	/// constructor;
	PEX_Enum		(
		PrpMdl*		pa_mdl,		/**< father model */
		PrpNode*	pa_fth,		/**< father item; NULL for top level */
		QString		stra_name,	/**< name of entry */
		QString		stra_descr,	/**< description of entry */
		unsigned	init_idx,	/**< index of initally selected entry */
		QStringList	ql_init		/**< list of enumeated values */
		);


	/// destructor;
	virtual				~PEX_Enum		(void) {}


	/// request actual value in text form
	virtual QVariant		valAsText	(void)
	{	if (qsl_enum.count() == 0) return QVariant();
		return qsl_enum[i_index]; }
	/// request decoration for the value
	virtual	QVariant		valAsDecor	(void)
	{	return QVariant(); }
	/// request to change the value made by user
	virtual bool			changeVal	(QVariant new_value);
	/// create editor for this type of item
	virtual	QWidget*	editCreate	(
		QWidget *					parent,
		const QStyleOptionViewItem	&option
		);
	/// load data from item to editor
	virtual	void		editLoad	(
		QWidget *					editor
		);
	/// save data from editor to item
	virtual	void		editSave	(
		QWidget *					editor
		);
//	/// update geometry for the editor
//	virtual	void		editResize	(
//		QWidget *					editor,
//		const QStyleOptionViewItem	&option
//		);
	/// informed about a click on associated icon
	virtual void		editIcon	(PrpView * prp_v, QModelIndex the_idx);


	/// gets the value of this entry
	inline unsigned		value		(void)
	{ return i_index; }
	/// sets the value of this entry
	inline void			setValue	(unsigned u_new_value)
	{ if (i_index >= qsl_enum.count()) i_index = qsl_enum.count() - 1;
		i_index = u_new_value; }


	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class PEX_Enum	*/

/*  CLASS    =============================================================== */
//
//
//
//
#endif // __PRPEX_ENUM_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
